package cn.com.scan.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import cn.com.scan.R;
import cn.com.scan.config.Config;

public class MainActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.import_buttton).setOnClickListener(viewClick);
        findViewById(R.id.export_button).setOnClickListener(viewClick);
        findViewById(R.id.check_button).setOnClickListener(viewClick);
        findViewById(R.id.keshi_check_button).setOnClickListener(viewClick);
        findViewById(R.id.keshi_shiyong_check_button).setOnClickListener(viewClick);


    }

    public View.OnClickListener viewClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.import_buttton:
                    Intent  importIntent=new Intent(MainActivity.this,ImprotStorageActivity.class);
                    startActivity(importIntent);
                    break;
                case R.id.export_button:
                    Intent  exportIntent=new Intent(MainActivity.this,ExportStorageActivity.class);
                    startActivity(exportIntent);
                    break;
                case R.id.check_button:
                    Intent  checkIntent=new Intent(MainActivity.this,CheckActivity.class);
                    startActivity(checkIntent);
                    break;
                case R.id.keshi_check_button:
                    Intent  keshiIntent=new Intent(MainActivity.this,KeShiCheckActivity.class);
                    startActivity(keshiIntent);
                    break;
                case R.id.keshi_shiyong_check_button:
                    Intent  keshiYongIntent=new Intent(MainActivity.this,UseCheckActivity.class);
                    startActivity(keshiYongIntent);
                    break;


            }
        }
    };

    @Override
    protected void broadcastExit() {
        this.finish();
    }

    @Override
    protected void capturePic(String codeStr) {

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
            alertBuilder.setTitle("提示");
            alertBuilder.setMessage("您确定退出");
            alertBuilder.setPositiveButton("退出",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            arg0.dismiss();
                            Intent intent = new Intent();
                            intent.setAction(Config.Exit_Program_TAG);
                            sendBroadcast(intent);
                        }
                    });
            alertBuilder.setNegativeButton("取消",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            arg0.dismiss();
                        }
                    });
            alertBuilder.show();
        }
        return false;
    }
}
